using System;
using System.Reflection;
using MetaObjects.Contracts;

namespace MetaObjects.Core
{
	public class PropertyInfoProvider : MetaFieldProvider<PropertyInfo>
	{
		protected override IMetaField GetMetaField(PropertyInfo field)
		{
			MetaField metaField = new MetaField(field.Name)
          	{
          		DisplayName = field.Name,
          		ReadOnly = !field.CanWrite,
          		GetField = entity => field.GetValue(entity, new object[0]),
          		SetField = (entity, value) => field.SetValue(entity, value, new object[0]),
				DefaultValue = field.PropertyType.IsValueType ? Activator.CreateInstance(field.PropertyType) : null,
          	};

			//DescriptionAttribute descriptionAttribute = field.GetInterfaceAttribute<DescriptionAttribute>();
			//if (descriptionAttribute != null)
			//{
			//    metaField.Description = descriptionAttribute.Description;
			//}
			
			//RequiredAttribute requiredAttribute = field.GetInterfaceAttribute<RequiredAttribute>();
			//metaField.Required = requiredAttribute != null;
			return metaField;
		}
	}
}